<?php
include('class/class_connect.php');
include('class/class_page.php');
include('class/class_address.php');
include('class/class_workdays.php');
include('class/class_rating.php');
include('class/abstract/class_mainObjectInfo.php');
include('class/city_rus.php');
include('class/class_checkGetData.php');
include('class/class_prices.php');

$aCheck=new checkGetData('f');
$aCheck->checkTableId($_GET['city'], $_GET['id']);

session_start();
if($_SESSION['login']=='zhendos')$admin=true;
if(isset($_POST['editStatus']) && $admin)
{
	$aConnect=new connect('f');
	$aConnect->update_data($_GET['city'], "status='".$_POST['status']."'", "WHERE id='".$_GET['id']."'");
}

class aFirmPage extends page
{
	var $row=array();
	var $cityRus;
	var $prices=array();
	function __construct()
	{
		$aConnect=new connect('p');
		$this->prices=mysql_fetch_array($aConnect->select_all($_GET['city'], "WHERE firms_id='".$_GET['id']."'"));
		$aConnect=new connect('f');
		$this->row=mysql_fetch_array($aConnect->select_all($_GET['city'], "WHERE id='".$_GET['id']."'"));
		$this->cityRus=new city_rus_class();
		parent::__construct();
	}
	function title()
	{		echo  $this->prices['tab_name'].' ';
		echo $this->row['name'].' '.$this->cityRus->city_rus_im($_GET['city']);
	}
	function maincontent()
	{		echo ('
		<link rel="stylesheet" type="text/css" href="style/price.css" />
        <div class="route">
        	<div class="routeEl">
				<a href="division.php?city='.$_GET['city'].'&division='.$this->row['division'].'">'.$this->row['division'].'</a>
			</div>
			<div class="routeEl">
				<a href="firms_list.php?city='.$_GET['city'].'&subdiv='.$this->row['subdiv'].'">'.$this->row['subdiv'].'</a>
			</div>
			<div class="routeEl">
				<a href="firms.php?city='.$_GET['city'].'&id='.$_GET['id'].'">'.$this->row['name'].'</a>
			</div>
			<div class="routeEl">
				'.$this->prices['tab_name'].'
			</div>
		</div>
		');
		$aFirmInfo=new aFirmInfo($this->row);
			$tabs=explode('`', $this->prices['stext']);
			for($i=1; $i<=count($tabs); $i++)
			{				$tabEls=explode('~', $tabs[$i-1]);
				$tabNames[$i]=$tabEls[0];			}
		echo ('
			<div class="priceTabs">
			');
			foreach($tabNames as $page=>$name)
			{				$class="priceTab";				if($page==$_GET['page'])$class="priceTabChosen";				echo ('
				<div class="'.$class.'">
					<a href="prices.php?city='.$_GET['city'].'&id='.$_GET['id'].'&page='.$page.'">'.$name.'</a>
				</div>
				');			}
			echo ('
			</div>
		');
		echo ('
		<div class="prices">
			<div class="showPrices">
		');
			if(!$_GET['page'])$limit=array(1,1);
			else $limit=array(1,$_GET['page']);
			$aShowPrice=new showPrice($this->prices['stext']);
		    $aShowPrice->showPrices($this->prices['stext'], false, false, $limit);
		echo ('
			</div>
		</div>
		');
	}
}



class aFirmInfo extends mainObjectInfo
{
	var $row;
	function __construct($row=array())
	{
		$this->row=$row;
		parent::__construct();
	}
	function showPic()
	{
		echo ('
		<img src="pictures/firmspics/'.$_GET['city'].'/'.$this->row['id'].'.jpg" title="'.$this->name.'">
		');
		$aFirmRating=new rating('f');
		$aFirmRating->rating($_GET['city'], $this->row['id']);
	}
	function showAddress()
	{
		$address=new address();
		$address->showSeveralAddresses($this->row['address'], $this->row['link']);
	}
	function showshort()
	{
		echo $this->row['short'];
	}
	function showName()
	{
		echo $this->row['name'];
	}
}
class showPrice extends prices
{
	function showPrices($tables, $a, $b, $limit){
		parent::showTables($tables, $a, $b, $limit);
	}
	function showTd($tdClass, $tdId, $tdValue, $temp='')
	{
		if($tdClass=='img')
			echo '<img src="pictures/pricepics/'.$_GET['city'].'/'.$_GET['id'].'/'.$tdId.'.jpg?'.rand().'" />';
		elseif($tdClass=='name' || $tdClass=='brend' || $tdClass=='model')
			echo '<a href="products.php?city='.$_GET['city'].'&product='.$tdValue.'">'.$tdValue.'</a>';
		else
			echo $tdValue;
	}
	function showHeader($table, $header=array())
	{
		$headerEmty=true;
		foreach($header as $key=>$vol)
		{
			if($vol && $vol!='')$headerEmty=false;
		}
		if($header && !$headerEmpty)
		{
			echo ('
			<tr id="headerTr'.$table.'" class="headerTr">
			');
			for($i=1; $i<=count($header); $i++)
			{
				echo ('
				<td id="headerTd'.$table.$i.'" class="headerTd">
					'.$header[$i-1].'
				</td>
				');
			}
			echo ('
			</tr>
			');
		}
	}
	function showTabName($tabName, $table)
	{
		echo ('
		<h3>'.$tabName.'</h3>
		');
	}
	function showColType($table, $colType){}
}

$aPage=new aFirmPage();

?>